﻿// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/classDetailsView/classDetailsView.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            // TODO: Initialize the page here.

            //set title to course name
            element.querySelector('.pagetitle').innerText = options.item.subject
                + options.item.catalog_nbr + ": "
                + options.item.course_title;
            var map;
            var venue;
            Microsoft.Maps.loadModule('Microsoft.Maps.Map', { callback: initMap, culture: 'en - us', homeRegion: 'US' });
            function initMap() {

                var mapOptions =
                {
                    credentials: "Al97SkFEXrSW5tPaTEaFV3ztz9EYnGU5cNejANcn8yMPQyy4Wbwfl-eSO7ifxkEX"
                };

                map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);
                Microsoft.Maps.loadModule('Microsoft.Maps.VenueMaps', { callback: venuemapsModuleLoaded });
            }
            function venuemapsModuleLoaded() {

                // Create the venue map
                var vmaps = new Microsoft.Maps.VenueMaps.VenueMapFactory(map);

                vmaps.create({ venueMapId: 'hcl-cornelluniversity', success: SetVenue });


            }

            function SetVenue(venueObj) {
                venue = venueObj;
                ShowVenue();
            }

            function ShowVenue() {
                // Set the map view 
                map.setView(venue.bestMapView);
                venue.show();
            }

        },

        unload: function () {
            // TODO: Respond to navigations away from this page.
        },

        updateLayout: function (element, viewState, lastViewState) {
            /// <param name="element" domElement="true" />

            // TODO: Respond to changes in viewState.
        }
    });
})();
